﻿<%@ Page Title="documentinfo" Language="C#" MasterPageFile="~/EasyUI.master" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="lcsign.Web.documentinfo.List" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    
    <script type="text/javascript">
        var did = "";
        var uid = "<%=uid%>";
        $(function () {
            InitGird();
            
        });
        //初始化流程下拉列表
        function InitDDL() {
            $('#cc').combobox({
                url: 'GetDoc.ashx?action=bindDDL',
                valueField: 'did',
                textField: 'dname',
                panelHeight: "auto",
                onLoadSuccess: function () { //数据加载完毕事件
                    var data = $('#cc').combobox('getData');
                    if (data.length > 0) {
                        $("#cc").combobox('select', data[0].did);
                    }
                }

            });
           
        }
        //初始化表格
        function InitGird() {
            $('#tt').datagrid({
                title: '文档列表', //表格标题
                url: 'GetDoc.ashx', //请求数据的页面
                sortName: 'ddatetime', //排序字段
                idField: 'did', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect: true,
                method: 'post',
                columns: [[
                    { field: 'ckb', checkbox: true },
                    { title: '文档名', field: 'dtitle', width: 80, sortable: true },
                    { title: '状态', field: 'dstatus', width: 80 },
                    { title: '上传人', field: 'uname', width: 80 },                    
                    { title: '上传时间', field: 'ddatetime', width: 150 }
                    ,
                    {
                        title: '操作', field: 'did', width: 80, formatter: function (value, row, index) {
                            //return '&nbsp;<a style="color:red" href="javascript:" onclick="$(this).parent().click();removeUser();return false;">删除</a>';
                            //return "&nbsp;<a style='color:red' href='../../documentTransfer/DocumentSubmit.aspx?id=" + row.did + "' target='_block'>提交审核</a>"
                            //    + "&nbsp;<a style='color:red' >查看</a>";

                            return "&nbsp;<a style='color:red' href='javascript:' onclick='$(this).parent().click();submitCheck("+row.did+");return false;'>提交审核</a>";

                            
                        }
                    }
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "querymy" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号
            });


        }

        //提交审核 
        function submitCheck(id) {
            //var row = $('#tt').datagrid('getSelected');
            //if (row == null) {
            //    $.messager.alert("提示", "请选择要提交的行！", "info");
            //}
            //if (row) {
            //    var DocumentID = row.did;
            //    if (DocumentID != "") {
            //       var url = encodeURI("<%=mHttpUrlRoot %>" + "documentTransfer/DocumentSubmit.aspx?id=" + DocumentID);
            //      $.messager.alert("提示", url, "info");    
            //  }
            //}

            if (id != "") {
                var url = encodeURI("<%=mHttpUrlRoot %>" + "documentTransfer/DocumentSubmit.aspx?id=" + id);
                //$.messager.alert("提示", url, "info");
                top.addTab("提交审核", url, "icon-edit");
            }
        }

        function newUser() {
            //清空内容  
            $('#fm').form('clear');
            InitDDL();
            $('#dlg').dialog('open').dialog('setTitle', '添加文档');
            document.getElementById("test").value = "add";
        }

        //修改管理员  
        function editUser() {
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要修改的行！", "info");
            }
            if (row) {
                $('#dlg').dialog('open').dialog('setTitle', '修改文档');
                document.getElementById("test").value = "modify";
                $('#fm').form('load', row);
                var DocumentID = row.upfile;
                if (DocumentID != "") {
                    var url = encodeURI("<%=mHttpUrl %>" + "FileLoad.aspx?DocumentID=" + DocumentID);
                    iStylePDF.HttpClient.DownLoadToFile(url);
                }
            }
        }
        //添加        
        function saveUser() {
            var test = document.getElementById("test").value;
            var f = $('#fm');
            if (test == "add") {
                var date = new Date();
                did = uid + date.getTime() + ".pdf";
                var url = encodeURI("<%=mHttpUrl %>" + "FileSave.aspx?DocumentID=" + did);
                var result = iStylePDF.HttpClient.UpLoadToServer(url);
                if (result == 200) {
                    f.form('submit', {
                        url: "GetDoc.ashx?action=" + test + "&did=" + did,
                        onSubmit: function () {
                            return $(this).form('validate');
                        },
                        success: function (result) {
                            if (result.indexOf("T") == 0) {
                                $('#dlg').dialog('close');
                                $.messager.alert("提示", "恭喜您，信息添加成功", "info");
                                $('#tt').datagrid('reload');
                            }
                            else if ((result.indexOf("F") == 0)) {
                                $.messager.alert("提示", "添加失败，请重新操作！", "info");
                                return;
                            }
                            else if ((result.indexOf("L") == 0)) {
                                $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                top.location = '/index.aspx';
                                return;
                            }
                        }
                    });
                }
                else {
                    $.messager.alert("提示", "上传文件失败，返回值为" + result, "info");
                }
            } else {
                did = $("#upfile").val();
                var url = encodeURI("<%=mHttpUrl %>" + "FileSave.aspx?DocumentID=" + did);
                var result = iStylePDF.HttpClient.UpLoadToServer(url);
                if (result == 200) {
                    $('#fm').form('submit', {
                        url: "GetDoc.ashx?action=" + test,
                        onSubmit: function () {
                            return $(this).form('validate');
                        },
                        success: function (result) {
                            if (result.indexOf("T") == 0) {
                                $('#dlg').dialog('close');
                                $('#tt').datagrid('clearSelections');
                                $.messager.alert("提示", "恭喜您，信息修改成功", "info");
                                $('#tt').datagrid('reload');

                            }
                            else if ((result.indexOf("F") == 0)) {
                                $.messager.alert("提示", "添加失败，请重新操作！", "info");
                                return;
                            }
                            else if ((result.indexOf("L") == 0)) {
                                $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                top.location = '/index.aspx';
                                return;
                            }
                        }
                    });
                }
                else {
                    $.messager.alert("提示", "上传文件失败，返回值为" + result, "info");
                }
            }
        }
        function removeUser() {
            var test = document.getElementById("test").value = "delete";
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要删除的行！", "info");
            }
            if (row) {
                $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                    if (r) {
                        $('#fm').form('submit', {
                            url: 'GetDoc.ashx?did=' + row.did + "&action=" + test,
                            onSubmit: function () {
                                //return $(this).form('validate');  
                            },
                            success: function (result) {
                                if (result.indexOf("T") == 0) {
                                    $('#dlg').dialog('close');
                                    $('#tt').datagrid('clearSelections'); //清空选中的行  
                                    $.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                    //alert('恭喜您，信息删除成功！')  
                                    // close the dialog  
                                    $('#tt').datagrid('reload');
                                    //$('#fm').form('submit');

                                }
                                else if ((result.indexOf("F") == 0)) {
                                    $.messager.alert("提示", "删除失败，请重新操作！", "info");
                                    return;
                                }
                                else if ((result.indexOf("L") == 0)) {
                                    $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                    top.location = '/index.aspx';
                                    return;
                                }

                            }

                        });
                    }
                })
            }
        }
        function getQueryParams(queryParams) {
            var stitle = $("#stitle").val();
            var StartTime = $("#StartTime").datebox("getValue");
            var EndTime = $("#EndTime").datebox("getValue");
            queryParams.stitle = stitle;
            queryParams.StartTime = StartTime;
            queryParams.EndTime = EndTime;
            return queryParams;
        }
        //增加查询参数，重新加载表格  
        function reloadgrid() {
            //查询参数直接添加在queryParams中      
            var queryParams = $('#tt').datagrid('options').queryParams;
            getQueryParams(queryParams);
            $('#tt').datagrid('options').queryParams = queryParams;
            $("#tt").datagrid('reload');
        }


    </script>
    <script type="text/javascript" language="javascript" for="iStylePDF" event="OnApplicationCreate(App)">
        //控件创建完成事件
        //控件使用的语言
        var lcid = App.Options.Lcid;
        //控件是否高亮域
        //App.Options.HighlightField = false;
        //隐藏下侧的导航工具栏
        App.Options.NavBarVisible = false;
        //隐藏左侧的命令工具栏
        App.Options.TabCommandBarVisible = false;
        //是否允许键盘快捷键操作
        App.Options.EnableAccelerator = true;
        //是否允许打开的文档记录历史记录中
        App.Options.HistoryEnabled = false;
        //设置单文档模式
        App.Options.DocumentsLayout = 0;
        //是否显示起始页
        App.Options.StartPageVisible = false;
        //打开文档100%显示
        //App.Options.PageZoomMode = 1;
        //App.Options.UserName = "青岛信元物和供应链有限公司";
        App.Options.UserName = "艾思玳尔测试";


    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    
    <table id="tt">
    </table>
    <div id="tab_toolbar" style="padding: 4px;">
        <table cellpadding="0" cellspacing="0" style="width: 100%">
            <tr>

                <td style="padding-left: 2px">
                    <a href="#" onclick="newUser();" id="a_add"
                        class="easyui-linkbutton" iconcls="icon-add">添加</a>
                    <a href="javascript:void(0)" onclick="editUser() " class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
                    <a href="#" onclick="removeUser();return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">删除</a>
                    
                </td>
                <td style="text-align:left; padding-right: 15px">
                    <div class="fitem" style="width: auto;">
                        名称:<input id="stitle" name="stitle" type="text" />
                        时间从:  
           <input id="StartTime" class="easyui-datebox" style="width: 100px" />
                        到:  
           <input id="EndTime" class="easyui-datebox" style="width: 100px" /><a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reloadgrid()">查找</a>
                    </div>

                    
                </td>
            </tr>
        </table>

    </div>
    <div id="dlg" class="easyui-dialog" style="width: 1000px; height: 500px; padding: 10px 20px"
        data-options="closed:true,buttons:'#dlg-buttons',shadow:false">

        <form id="fm" method="post">

            <div style="position: relative;z-index:99999" class="fitem">
                <label>标题：</label><input id="dtitle" name="dtitle" class="easyui-validatebox" data-options="required:true" />&nbsp;
                &nbsp;请选择审核流程：<input id="cc" name="cc"  style ="width:120px;" /> 
            </div>
            <div class="fitem" >
                图片上传方式： 文件--》创建PDF-->从文件                              
                <input name="Test" id="test" type="hidden" />
                <input name="upfile" id="upfile" type="hidden" />
                <input name="did" id="did" type="hidden" />
                <input id="key" name="key" onkeydown="if(event.keyCode==13)reloadgrid()" type="hidden" />
                
            </div>
           
        </form>
         <div style="height:340px; z-index:-1;position: relative;">
                <object id="iStylePDF" width="100%" height="100%" style="z-index:-100;position: relative;" classid="CLSID:7017318C-BC50-4DAF-9E4A-10AC8364C315" codebase="iStylePDF.cab#version=3,0,6,2155">
                    
                </object>
            </div>
    </div>
    <div id="dlg-buttons">
        
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveUser()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
    </div>
</asp:Content>

